package interrupt;

import java.io.IOException;

public class IOInterruptDemo {
    public static void main(String[] args) throws IOException {
        Thread thread = new Thread(() -> {
            System.out.println("thread ready");
            try {
                int read = System.in.read();
                System.out.println("read -> " + read);
                System.out.println("read completed");
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println("thread exit");
        });
        thread.start();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(thread.getState());
        System.out.println("interrupt");
        thread.interrupt();
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(thread.isInterrupted());
        System.in.close();
    }
}
